package com.mall.search.server.controller;

import com.mall.common.core.domain.Result;
import com.mall.search.server.service.EsSearchService;
import com.mall.search.server.vo.SearchParam;
import com.mall.search.server.vo.SearchResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

@RequestMapping("/")
@RestController
public class EsSearchController {

    @Autowired
    private EsSearchService esSearchService;


    /**
     * 查询es，根据查询条件searchParam,返回封装结果集result
     * @param searchParam
     * @return
     */
    @PostMapping("/")
    public Result<SearchResult> search(SearchParam searchParam) throws IOException {
        SearchResult searchResult = esSearchService.search(searchParam);
        return Result.success(searchResult);
    }
}
